
/* Replication materials for "What Kinds of Political Regimes Subsidize Fuel Consumption?" 
Matthew Fails
fails@oakland.edu
Oakland University
Forthcoming in The Extractive Industries and Society
*/

use "c:\data\EIS_Replication_Dataset.dta", replace

****
*Some variable and ID creation
****

*Create some id variables to identify years following a transition from closed to electoral autocracy
sort ccode year
by ccode: gen lagreg = L.v2x_regime
by ccode: gen yrchange = (v2x_regime) - (lagreg) 
*when yrchange == 1, this signals a one unit regime improvement
*if yrchange==1 & v2x_regime==1, then this identifies a year where CA regime transitioned to an EA regime
gen EAchange_yr = 1 if yrchange==1 & v2x_regime==1
label var EAchange_yr "year of a transition between CA to EA regime"

*generate a measure of yearly change in subsidy in year prior to CA-to-EA transition 
by ccode: gen diff_pretrans = (l.pdiff_a_USD - l2.pdiff_a_USD) if EAchange_yr == 1	
label var diff_pretrans "Change in subsidy size year prior to CA-EA transition"

*generate a measure of yearly change in subsidy in year immediately following CA-to-EA transition
by ccode: gen diff3 = (f.pdiff_a_USD - pdiff_a_USD) if EAchange_yr == 1 
label var diff3 "Change in price gap from EA transition year to t+1"

*create an ID for CA-to-EA trans 
by ccode: gen CA_EA_trans = 0
by ccode: replace CA_EA_trans = 1 if yrchange==1 & v2x_regime<=1
tab CA_EA_trans, mis
label var CA_EA_trans "ID variable for the year in which a closed autocracy transitioned to an electoral autocracy"
	
*create an ID for the three categories (CA-to-EA transition observations, other autocracies, and democracies)
gen ID2 = .
replace ID2 = 1 if CA_EA_trans==1
replace ID2 = 2 if CA_EA_trans == 0 & dem_Vdem!=1 & v2x_regime!=.
replace ID2 = 3 if CA_EA_trans == 0 & dem_Vdem==1
tab ID2
label define ID2_1 1 "Closed to Electoral Autocracy" 2 "Other Autocracies" 3 "Democracies", modify
label values ID2 ID2_1	
	
*Create an ID for oil producers, based on non-zero oil income production per capita, Ross and Mahdavi (2015) data
gen oil_ID = 0 if oil_dummy==0
replace	oil_ID = 1 if oil_dummy==1
label define oil_ID_1 0 "Non-Oil Producer" 1 "Oil Producer", modify
label values oil_ID oil_ID_1
	
*Create combined measure that uses RHM for years where present, my measure for others (used in robustness analysis)
gen gap_comb = pdiff_a_USD if RHMbmgap==.
replace gap_comb = RHMbmgap if RHMbmgap!=.
label var gap_comb "Combined price gap measure"
	
	
************************************************
*Figure 1 published manuscript uses VDem data to plot evolution of political regimes
*See separate data call at the end of this replication file to re-create this figure
************************************************
	
************************************************
*Figures 2-6 in published manuscript
************************************************

*Figure 2 - histogram of subsidy measure
graph twoway (hist pdiff_a_USD if pdiff_a_USD<=0, freq barw(.08) bin(10) fcolor(gs0) lcolor(gs0) legend(order(1 "Price gap is negative" 2 "Price gap is positive")pos(1) ring(0))) ///
(hist pdiff_a_USD if pdiff_a_USD>0, xlabel(-1(1)3.5) ylabel() freq barw(.08) fcolor(gs8) lcolor(gs8) ///
scheme(plotplain) xtitle("Net Implicit Tax on Gasoline, in USD per Liter") ///
	title("Figure 2: Net Implicit Tax on Gasoline, reported in US Dollars per Liter", pos(11)) ///
	note(" " "Data calculated by author following price gap approach." "Plot reports all yearly observations 1990-2014 for a global sample.") xsize(6))
	
*Fig 3 - compares pre and post transition yearly changes
 twoway (kdensity diff_pretrans, color(gs0%90)  recast(area)) (kdensity diff3, color(gs0%50) recast(area) scheme(plotplain) xtitle("One Year Change in Net Implicit Fuel Tax" "for Regimes Transitioning from Closed to Electoral Autocracy") xlabel(-.5 (.1) .5) xline(0, lcolor(red)) legend(order(1 "Pre-EA transition year" 2 "Post-EA transition year") pos(2) ring(0)) ytitle("Density") note("Note: Plot depicts distribution of one-year change in size of fuel subsidies for year" "before and after transition from 'closed' to 'electoral' autocracy (N = 59)", size(small)) title("Figure 3: Comparing Yearly Change in Subsidies Before and After Regime Transition"))

 
 *Fig 4 - avg by regime, oil status
graph hbar (mean) pdiff_a_USD, over(oil_ID, label(nolabels)) over(ID2, gap(100)) bar(1, color(gs0)) bar(2, color(gs8)) scheme(plotplain) ///
	ytitle("Average Net Implicit Tax on Gasoline, in USD per liter") asyvars showyvars ///
	legend(order(1 "Non-oil producers" 2 "Oil producers") pos(2) ring(0)) yline(0) title("Figure 4: Regimes and Average Consumer Gasoline Subsidy" "Separated by Oil Producer Status.") ///
	note("Note: Figure separates autocratic regime-years that transition from 'closed' " ///
	"to 'electoral' autocracies from all other autocratic regime-years and" ///
	"democratic regime-years. Oil producer status measured as non-zero oil" ///
	"income per capita using Ross and Mahdavi (2015) data. See text for details.", size(small))		
	
*Fig 5 - TWFE estimates
*1 electoral democracy index
xtreg pdiff_a_USD l.v2x_polyarchy_V10 l.oil_new l.lincome_new l.urb_pct_WBopen l.oil_price_2000 i.year, fe robust
est store m1
*2 binary democracy measure
xtreg pdiff_a_USD l.dem_Vdem l.oil_new l.lincome_new l.urb_pct_WBopen l.oil_price_2000 i.year, fe robust
est store m2
*3 disaggregate autocratic types (closed autocracy as baseline category)
xtreg pdiff_a_USD l.ea_Vdem l.dem_Vdem l.oil_new l.lincome_new l.urb_pct_WBopen l.oil_price_2000 i.year, fe robust
est store m3
*4 conditional / interactive model, with interaction terms for each regime type (x) oil income
xtreg pdiff_a_USD l.ea_Vdem l.dem_Vdem l.oil_new c.l.ea_Vdem#c.l.oil_new c.l.dem_Vdem#c.l.oil_new l.lincome_new l.urb_pct_WBopen l.oil_price_2000 i.year, fe robust
est store m4

coefplot m1, keep(L.v2x_polyarchy_V10 L.oil_new) xline(0) levels(95) msize(med) bylabel("1. Electoral Democracy" "Index") ///
	|| m2, keep(L.dem_Vdem L.oil_new) xline(0) levels(95) msize(large) bylabel("2. Democracy" "(Binary)") ///
	|| m3, keep(L.ea_Vdem L.dem_Vdem L.oil_new) xline(0) levels(95) msize(large) bylabel("3. Disaggregate" "Autocracy") ///
	|| m4, keep(L.ea_Vdem L.dem_Vdem L.oil_new cL.ea_Vdem#cL.oil_new cL.dem_Vdem#cL.oil_new) xline(0) levels(95) msize(large) bylabel("4. Conditional Model" " ")  ///
	coeflabels(L.v2x_polyarchy_V10 = "Electoral Democracy Index" L.ea_Vdem = "Electoral Autocracy (binary)" L.dem_Vdem = "Democracy (binary)" L.oil_new = "(log) Oil income per capita" ///
	L.lincome_new = "(log) Income per capita" L.urb_pct_WBopen = "Urban Population (%)" L.oil_price_2000 = "Oil Price" ///
	L.inc_sq = "(log) Income per capita squared" L.cg = "Central Government Debt" ///
	cL.ea_Vdem#cL.oil_new = "Electoral Autocracy (x) Oil Income" ///
	cL.dem_Vdem#cL.oil_new = "Democracy (x) Oil Income", labsize(med)) ///
	byopts(row(2) note(" " "Dependent variable is author calculated measure of net implicit tax on gasoline, in dollars per liter." ///
	"Sample includes 161 countries, 1990-2014, or 3,492 observations; models include measures of urban population" ///
	"share, oil price, and country and year fixed effects, though these are not reported in the plot, and robust standard errors.") ///
	title("Figure 5: Two-Way Fixed Effects Regression Coefficients with 95% Confidence Intervals" , pos(11))) ciopts(lwidth(*1 *2)) ///
	xsize(8) scheme(plotplain)
	
*Fig 6 - substantive effects	

*estimate these substantive effects when interacting democracy with the oil income variable too
*EA, oil 0 to 100
xtreg pdiff_a_USD l.ea_Vdem l.dem_Vdem l.oil_new c.l.ea_Vdem#c.l.oil_new c.l.dem_Vdem#c.l.oil_new l.lincome_new l.urb_pct_WBopen l.oil_price_2000 i.year, fe robust
margins, at (l.ea_Vdem=(1) l.dem_Vdem=(0) l.oil_new=(0,4.6)) atmeans level(95) contrast(at effects) post
est store compare_1
*CA, oil 0 to 100
xtreg pdiff_a_USD l.ea_Vdem l.dem_Vdem l.oil_new c.l.ea_Vdem#c.l.oil_new c.l.dem_Vdem#c.l.oil_new l.lincome_new l.urb_pct_WBopen l.oil_price_2000 i.year, fe robust
margins, at (l.ea_Vdem=(0) l.dem_Vdem=(0) l.oil_new=(0,4.6)) atmeans level(95) contrast(at effects) post
est store compare_2
*Dem, oil 0 to 100
xtreg pdiff_a_USD l.ea_Vdem l.dem_Vdem l.oil_new c.l.ea_Vdem#c.l.oil_new c.l.dem_Vdem#c.l.oil_new l.lincome_new l.urb_pct_WBopen l.oil_price_2000 i.year, fe robust
margins, at (l.ea_Vdem=(0) l.dem_Vdem=(1) l.oil_new=(0,4.6)) atmeans level(95) contrast(at effects) post
est store compare_3

coefplot ///
(compare_1, label("Electoral autocracy") msize(large)) ///
(compare_2, label("Closed autocracy") msize(large)) ///
(compare_3, label("Democracy") msize(large)) ///
, scheme(plotplain) xline(0) level(95) xtitle(" ") ///
ytitle(" ") ///
ylabel(.) ///
note(" " "Note: Estimates are expressed as 95% confidence intervals of the change in" ///
"the expected value of Net Implict Taxes on Gasoline in USD per liter. Predicted" ///
"values calculated while holding all other explanatory variables at mean values.", size(small)) ///
title("Figure 6: Predicted Change in Net Implicit Tax on Liter of Gasoline" "When Oil Income per capita Increases from $0 to $100") aspectratio(.5) legend(pos(8) ring(0))


*Supplemental Materials / Appendix 

*Tabular version of Fig 5
esttab m1 m2 m3 m4 using a1.rtf, b(3) se(3) label replace star(+ 0.10 * 0.05 ** 0.01) ///
title("Two-Way Fixed Effect Regression Estimates, from Figure 5") ///
addnote("Note:")

* Core robustness from first submission
*control for NOC and CG (central govt debt)
xtreg pdiff_a_USD l.ea_Vdem l.dem_Vdem l.oil_new c.l.ea_Vdem#c.l.oil_new c.l.dem_Vdem#c.l.oil_new l.lincome_new l.urb_pct_WBopen l.oil_price_2000 l.cg l.noc i.year, fe robust
est store r1
*autocracy only - no dem_Vdem or interaction variable
xtreg pdiff_a_USD l.ea_Vdem l.oil_new c.l.ea_Vdem#c.l.oil_new l.lincome_new l.urb_pct_WBopen l.oil_price_2000 i.year if v2x_regime<=1, fe robust
est store r2
*no year FEs
xtreg pdiff_a_USD l.ea_Vdem l.dem_Vdem l.oil_new c.l.ea_Vdem#c.l.oil_new c.l.dem_Vdem#c.l.oil_new l.lincome_new l.urb_pct_WBopen l.oil_price_2000, fe robust
est store r3
*drop constant EA regimes (all EA, or never EA), in full sample
*generate an ID for panels that don't experience any sort of EA change 
sort ccode year
by ccode: egen meanEA = mean(ea_Vdem)
tab meanEA, mis
xtreg pdiff_a_USD l.ea_Vdem l.dem_Vdem l.oil_new c.l.ea_Vdem#c.l.oil_new c.l.dem_Vdem#c.l.oil_new l.lincome_new l.urb_pct_WBopen l.oil_price_2000 i.year if meanEA!=1 & meanEA!=0, fe robust
est store r4
*non-imputed price gaps
xtreg pdiff_a_USD l.ea_Vdem l.dem_Vdem l.oil_new c.l.ea_Vdem#c.l.oil_new c.l.dem_Vdem#c.l.oil_new l.lincome_new l.urb_pct_WBopen l.oil_price_2000 i.year if ppl_avg!=., fe robust
est store r5
*alternative DV measured
xtreg gap_comb l.ea_Vdem l.dem_Vdem l.oil_new c.l.ea_Vdem#c.l.oil_new c.l.dem_Vdem#c.l.oil_new l.lincome_new l.urb_pct_WBopen l.oil_price_2000 i.year, fe robust
est store r6

esttab r1 r2 r3 r4 r5 r6 using a2.rtf, b(3) se(3) label replace star(+ 0.10 * 0.05 ** 0.01) ///
title("Two-Way Fixed Effect Regression Estimates, Robustness Analysis") ///
addnote("Note:")

*Variable timing - different time periods (with dem interaction)


*This is a good discussion of Goodman Bacon in terms of different timing 
*https://blogs.worldbank.org/impactevaluations/what-are-we-estimating-when-we-estimate-difference-differences
*So, we need to think about what the appropriate break points are for timing: based on oil price trends?
*for now, break at certain era's of oil price (since this might drive incentive to subsidize); 1991-2000 for relative stability, 2001-2009 for rising prices, and 2010-2014 for dramatic decline

*1991-2000
xtreg pdiff_a_USD l.ea_Vdem l.dem_Vdem l.oil_new c.l.ea_Vdem#c.l.oil_new l.lincome_new l.urb_pct_WBopen l.oil_price_2000 i.year if year<2001, fe robust
est store r7
*2001-2009
xtreg pdiff_a_USD l.ea_Vdem l.dem_Vdem l.oil_new c.l.ea_Vdem#c.l.oil_new l.lincome_new l.urb_pct_WBopen l.oil_price_2000 i.year if year>=2001 & year<=2009, fe robust
est store r8
*2010-2014
xtreg pdiff_a_USD l.ea_Vdem l.dem_Vdem l.oil_new c.l.ea_Vdem#c.l.oil_new l.lincome_new l.urb_pct_WBopen l.oil_price_2000 i.year if year>2009, fe robust
est store r9

esttab r7 r8 r9 using a3.rtf, b(3) se(3) label replace star(+ 0.10 * 0.05 ** 0.01) ///
title("Two-Way Fixed Effect Regression Estimates, Exploring Variable Timing") ///
addnote("Note:")


*Scatterplot of 2 diff price gap measures
	scatter RHMbmgap pdiff_a_USD, ///
	scheme(plotplain) ytitle("Ross, Hazlett, and Mahdavi Price Gap") ///
	xtitle("Author Calculated Price Gap") ///
	title("Comparing Price Gap Measures, 2003-2014") note("r = 0.89, p < 0.001")
	

*Descriptive statistics
xtreg pdiff_a_USD ea_Vdem dem_Vdem oil_new lincome_new urb_pct_WBopen oil_price_2000 i.year, fe robust
sum pdiff_a_USD v2x_polyarchy_V10 ea_Vdem dem_Vdem oil_new lincome_new urb_pct_WBopen oil_price_2000 cg noc year if e(sample)
*Note that the obs # is higher than in the actual baseline models, given the lag structure		



***********************************************************
*Figure 1 - Evolution of Political Regimes
*(note: uses a different source dataset)
***********************************************************

use "c:\data\EIS_VDem_ROW_Fig1_RepData.dta", replace
egen num_ccode = nvals(cowcode), by(year) 
gen dem_Vdem = 1 if v2x_regime>1
gen ea_Vdem = 1 if v2x_regime==1
gen ca_Vdem = 1 if v2x_regime==0

bysort year: egen num_dem = sum(dem_Vdem)
bysort year: egen num_EA = sum(ea_Vdem)
bysort year: egen num_CA = sum(ca_Vdem)
*the above creates, by year, a count of the number of Dem, EA, and CA regimes
bysort year: gen share_dem = num_dem/num_ccode
graph twoway line  share_dem year
bysort year: gen share_ea = num_EA/num_ccode
graph twoway line  share_ea year
bysort year: gen share_ca = num_CA/num_ccode
graph twoway line  share_ca year
*graph together
graph twoway (line share_dem year) (line share_ea year) (line share_ca year, ///
title("Figure 1: The Evolution of Political Regimes, 1960-2019") ytitle("Share of Countries in the World") ///
legend(order(1 "Democracies" 2 "Electoral Autocracies" 3 "Closed Autocracies") pos(7) ring(0)) scheme(plotplain) ///
note("Note: Measure of political regimes drawn from Luhrmann, Tannenberg, and Lindberg (2019)", size(small))   )
